//
//  CTRequestFlip.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/1.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTRequestFlip.h"
#import "CTDebugManager.h"
#import "CTFile.h"



@implementation CTRequestFlip

//是否可以翻页
+(BOOL)isFlip:(id)info
{
    BOOL flipFlag = NO;
    
    @try {
        NSMutableDictionary * infoDic = (NSMutableDictionary *)info;
        NSString * nextPage = [NSString stringWithFormat:@"%@",[infoDic objectForKey:@"next_page"]];
        
        if ([nextPage isEqualToString:@"0"]) {
            flipFlag = NO;
        }else{
            flipFlag = YES;
        }
    }
    @catch (NSException *exception) {
        [CTDebugManager showErrorLogInfo:@"检测是否可以翻页，数据解析失败!"];
    }
   
    return flipFlag;
    
}

//获取翻页号码
+(NSString *)flipPageNumberWithlocalName:(NSString *)name localPath:(NSString *)path
{
    NSString * pageNumber = @"0";
    
    @try {
        NSMutableDictionary * localDic = [CTFile getDicFile:name fromDoc:CTFileDocLibrary fromPath:path];
        pageNumber = [NSString stringWithFormat:@"%@",[localDic objectForKey:@"next_page"]];
    }
    @catch (NSException *exception) {
         [CTDebugManager showErrorLogInfo:@"返回翻页数据解析失败!"];
    }
  
    return pageNumber;
}

//组装合并翻页数据
+(void)genFlipData:(NSDictionary *)info localName:(NSString *)name localPath:(NSString *)path
{
    @try {
     
        NSMutableDictionary * infoDic = [info mutableCopy];
        NSMutableDictionary * localDic = [CTFile getDicFile:name fromDoc:CTFileDocLibrary fromPath:path];
    
        NSMutableArray * localListArr = [localDic objectForKey:@"list"];
        NSMutableArray * infoListArr = [infoDic objectForKey:@"list"];
        
        for (NSDictionary * detailDic in infoListArr) {
            [localListArr addObject:detailDic];
        }
        
        if (infoListArr.count != 0 ||  infoListArr != nil)
        infoListArr = nil;
        
        [localDic setObject:localListArr forKey:@"list"];
        NSString * nextPage = [NSString stringWithFormat:@"%@",[infoDic objectForKey:@"next_page"]];
        [localDic setObject:nextPage forKey:@"next_page"];
     
        [CTFile cacheDicFile:localDic fileName:name saveDoc:CTFileDocLibrary savePath:path];
        
        infoDic = nil;
        localDic = nil;
    }
    @catch (NSException *exception) {
        [CTDebugManager showErrorLogInfo:@"检测翻页数据组装失败!"];
    }
    
}

@end
